package com.xin.ruanjian.omsystem.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.CardView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.gordonwong.materialsheetfab.DimOverlayFrameLayout;
import com.gordonwong.materialsheetfab.MaterialSheetFab;
import com.xin.ruanjian.omsystem.R;
import com.xin.ruanjian.omsystem.adapter.MainVpAdapter;
import com.xin.ruanjian.omsystem.app.MyApplication;
import com.xin.ruanjian.omsystem.bases.BaseActivity;
import com.xin.ruanjian.omsystem.utils.HttpUtils;
import com.xin.ruanjian.omsystem.view.Fab;
import com.xin.ruanjian.omsystem.view.TimeSelectDialog;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import devlight.io.library.ntb.NavigationTabBar;
import okhttp3.Call;

import static com.xin.ruanjian.omsystem.bases.Contants.SHOP_LIST;
import static com.xin.ruanjian.omsystem.bases.Contants.USER_LOGIN;

public class MainActivity extends BaseActivity {
    @BindView(R.id.tv_centerTitle)
    TextView tvCenterTitle;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.ntb_bottom)
    public NavigationTabBar ntbBottom;
    @BindView(R.id.vp_main)
    ViewPager vpMain;
    @BindView(R.id.iv_rightPic)
    ImageView ivRightPic;
    @BindView(R.id.fab)
    public Fab fab;
    @BindView(R.id.overlay)
    DimOverlayFrameLayout overlay;
    @BindView(R.id.fab_sheet)
    CardView fabSheet;
    @BindView(R.id.rl_bottom)
    public RelativeLayout rlBottom;
    private MaterialSheetFab<Fab> materialSheetFab;
    private MainVpAdapter mainVpAdapter;

    @Override
    protected void initContentView(Bundle bundle) {
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void initView() {
        initFab();
        initBottom();
    }

    @Override
    protected void initTitle() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void main() {

    }

    private void initBottom() {
        mainVpAdapter = new MainVpAdapter(context, getSupportFragmentManager(), 3);
        vpMain.setAdapter(mainVpAdapter);
        vpMain.setOffscreenPageLimit(3);
        final ArrayList<NavigationTabBar.Model> models = new ArrayList<>();
        models.add(
                new NavigationTabBar.Model.Builder(
                        getResources().getDrawable(R.drawable.ic_launcher),
                        getResources().getColor(R.color.colorSelected))
                        .title("推荐")
                        .build()
        );
        models.add(
                new NavigationTabBar.Model.Builder(
                        getResources().getDrawable(R.drawable.ic_launcher),
                        getResources().getColor(R.color.colorSelected))
                        .title("分类")
                        .build()
        );
//        models.add(
//                new NavigationTabBar.Model.Builder(
//                        getResources().getDrawable(R.drawable.ic_launcher),
//                        getResources().getColor(R.color.colorSelected))
//                        .title("订单")
//                        .build()
//        );
        models.add(
                new NavigationTabBar.Model.Builder(
                        getResources().getDrawable(R.drawable.ic_launcher),
                        getResources().getColor(R.color.colorSelected))
                        .title("个人")
                        .build()
        );

        ntbBottom.setModels(models);
        ntbBottom.setViewPager(vpMain, 0);

        //IMPORTANT: ENABLE SCROLL BEHAVIOUR IN COORDINATOR LAYOUT
        ntbBottom.setBehaviorEnabled(false);

        ntbBottom.setOnTabBarSelectedIndexListener(new NavigationTabBar.OnTabBarSelectedIndexListener() {
            @Override
            public void onStartTabSelected(final NavigationTabBar.Model model, final int index) {
            }

            @Override
            public void onEndTabSelected(final NavigationTabBar.Model model, final int index) {
                model.hideBadge();
            }
        });
        ntbBottom.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(final int position, final float positionOffset, final int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(final int position) {

            }

            @Override
            public void onPageScrollStateChanged(final int state) {

            }
        });
    }

    private void initFab() {
        View sheetView = findViewById(R.id.fab_sheet);
        View overlay = findViewById(R.id.overlay);
        int sheetColor = getResources().getColor(R.color.color_white);
        int fabColor = getResources().getColor(R.color.colorPrimary);

        // Initialize material sheet FAB
        materialSheetFab = new MaterialSheetFab<>(fab, sheetView, overlay,
                sheetColor, fabColor);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }


}
